package com.wu.login;

import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Constants;
import com.jfinal.config.Routes;
import com.jfinal.config.Handlers;
import com.jfinal.config.Plugins;
import com.jfinal.config.Interceptors;

import com.jfinal.core.JFinal;
import com.jfinal.kit.PropKit;
import com.jfinal.log.Logger;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.dialect.AnsiSqlDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;
import com.wu.stations.Stations;

/**
 * Created by Mian on 2015/12/30.
 */
public class WuConfig extends JFinalConfig {

    private static Logger log = Logger.getLogger(JFinalConfig.class);

    public void configConstant(Constants me){
        log.debug("读取配置文件信息");
        loadPropertyFile("config.properties");
        PropKit.use("config.properties");
        me.setViewType(ViewType.FREE_MARKER);
        me.setDevMode(true);
    }

    public void configRoute(Routes me){
        me.add("/",TestController.class,"/view/index");
        me.add("/view/user",TestController.class);
        me.add(new com.wu.config.Routers());
    }

    public void configPlugin(Plugins me){
        //mysql.driverClass
        C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("mysql.driverUrl"),PropKit.get("mysql.userName"),PropKit.get("mysql.passWord"),PropKit.get("mysql.driverClass"));
        me.add(c3p0Plugin);

        ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
        arp.setDialect(new AnsiSqlDialect());
        me.add(arp);
        arp.addMapping("pt_station","ids", Stations.class);
    }

    public void configInterceptor(Interceptors me){

    }

    public void configHandler(Handlers me){

    }

    public static void main(String [] args){
        JFinal.start("WebContent",8084,"/",5);
    }
}
